package cmd

import (
	"context"

	"github.com/gogf/gf/v2/net/ghttp"

	"github.com/gogf/gf/v2/frame/g"
	"github.com/gogf/gf/v2/os/gcmd"

	"gf-websocket/internal/router"
	"gf-websocket/internal/packed/websocket"
)

var (
	Main = gcmd.Command{
		Name:  "main",
		Usage: "main",
		Brief: "start http server",
		Func: func(ctx context.Context, parser *gcmd.Parser) (err error) {
			// 设置模板标签分隔符
			g.View().SetDelimiters("{{", "}}")
			//设置服务启动时间
			s := g.Server()
			//session使用memory

			websocket.StartWebSocket(ctx)


			//路由
			router.Init(s)
			s.BindStatusHandlerByMap(map[int]ghttp.HandlerFunc{
				404: func(r *ghttp.Request) {

				},
				403: func(r *ghttp.Request) {
					// 只清除缓冲区数据
					r.Response.ClearBuffer()
				},
				500: func(r *ghttp.Request) {

				},
			})
			s.Run()
			return nil
		},
	}
)
